package com.gzist.elderlyserviceplatform.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzist.elderlyserviceplatform.common.Result;
import com.gzist.elderlyserviceplatform.entity.dto.ListQueryPageDTO;
import com.gzist.elderlyserviceplatform.entity.po.NursingHome;
import com.gzist.elderlyserviceplatform.service.NursingHomeService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 养老院信息表
 */
@RestController
@Tag(name = "养老院信息管理")
@RequestMapping("/api/admin/nursingHome")
@RequiredArgsConstructor
public class NursingHomeControllerA {

    private final NursingHomeService nursingHomeService;

    @PostMapping("/add")
    @Operation(summary = "养老院信息增加", description = "NursingHome")
    public Result add(
            @RequestBody
            @Parameter(description = "养老院信息") NursingHome nursingHome
    ) {
        nursingHomeService.save(nursingHome);
        return Result.success("添加成功");
    }

    @PostMapping("/list")
    @Operation(summary = "养老院查询列表获取")
    public Result<Page<NursingHome>> list(
            @RequestBody
            @Parameter(description = "查询参数") ListQueryPageDTO listQueryPageDTO
    ) {
        return Result.success(nursingHomeService.list(listQueryPageDTO),"查询成功");
    }

    @PostMapping("/update")
    @Operation(summary = "养老院信息修改", description = "NursingHome")
    public Result update(
            @RequestBody
            @Parameter(description = "养老院信息") NursingHome nursingHome
    ){
        nursingHomeService.update(nursingHome);
        return Result.success("修改成功");
    }

    @GetMapping("/detail/{id}")
    @Operation(summary = "单个养老院信息查询", description = "传递养老院id,根据id获取养老院信息")
    public Result<NursingHome> query(
            @PathVariable
            @Parameter(description = "养老院id") String id
    ){
        return Result.success(nursingHomeService.getById(id),"查询成功");
    }

    @PostMapping("/delete/{id}")
    @Operation(summary = "养老院信息删除", description = "传递养老院id,根据id删除")
    public Result delete(
            @PathVariable
            @Parameter(description = "养老院信息id") String id
    ){
        nursingHomeService.removeById(id);
        return Result.success("删除成功");
    }

    @PostMapping("/batchDelete")
    @Operation(summary = "养老院信息批量删除", description = "传递养老院id集,根据id批量删除")
    public Result batchDelete(
            @RequestBody
            @Parameter(description = "养老院信息id") String[] ids
    ){
        nursingHomeService.removeByIds(Arrays.asList(ids));
        return Result.success("批量删除成功");
    }
}